home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / mpatrol / FAQ < prev    next >
Encoding:
Text File  |  2000-05-16  |  20.7 KB  |  376 lines

  1. FAQ FOR THE MPATROL LIBRARY
  2.  
  3.  
  4. This file contains frequently asked questions about the mpatrol library and
  5. their corresponding answers or solutions.
  6.  
  7.  
  8.  1. DOCUMENTATION
  9.  
  10.  Q. I can't seem to format the TeXinfo manual for mpatrol into anything that I
  11.     can view or print.  What am I doing wrong?
  12.  
  13.  A. You'll need to have the appropriate document formatting programs installed
  14.     on your system before you can do this, and even then you'll also need to
  15.     have suitable software for viewing or printing the formatted documents.  You
  16.     can download an archive containing the latest mpatrol manual in a variety of
  17.     formats from http://www.cbmamiga.demon.co.uk/mpatrol/ and this will also
  18.     contain a file telling you where to get programs that can be used to view or
  19.     print these files.  Alternatively, you can browse the latest mpatrol manual
  20.     on-line at the same site.
  21.  
  22.  Q. I'd like to convert the mpatrol manual to a different documentation format
  23.     but there is no support for that format in the Makefile.  How would I go
  24.     about doing this?
  25.  
  26.  A. Since TeXinfo is intended to be converted to other documentation formats it
  27.     should be fairly easy for you to find a tool which will convert it into your
  28.     desired format.  I plan to also provide the mpatrol manual in DocBook format
  29.     if and when a suitable TeXinfo to DocBook converter becomes available, but I
  30.     won't provide preformatted versions of the mpatrol manual in any other
  31.     format which isn't already supported.
  32.  
  33.  Q. Why is the reference card not centred in the middle of the page when I print
  34.     it?
  35.  
  36.  A. The reference card has three columns in landscape format and as a result
  37.     requires smaller margins than LaTeX normally uses.  When dvips converts the
  38.     DVI file to a postscript file it refers to a configuration file set up for
  39.     a specific printer so that it knows what that printer's capabilities are.
  40.     However, you can instruct dvips to offset the page by a given amount with
  41.     the -O option so that it appears centred when printed.  I find that
  42.     -O -0.75in,0.25in works for me.  Note that the default paper size for the
  43.     reference card is DIN A4, but you can change it to US letter in the LaTeX
  44.     source file.
  45.  
  46.  Q. How do I install the mpatrol manual as a GNU info file?
  47.  
  48.  A. Assuming you have the GNU info file built and copied to your system's info
  49.     file directory, you should use the install-info command to place an entry
  50.     for mpatrol in your system's GNU info directory file, otherwise the GNU info
  51.     reader may not be able to locate the mpatrol entry.  You may also need to
  52.     modify your INFOPATH environment variable if you installed the GNU info file
  53.     in a non-standard place.
  54.  
  55.  Q. How do I install the mpatrol manual pages?
  56.  
  57.  A. This is very system-dependent, but need only be done on UNIX systems since
  58.     they cannot be used on other platforms.  The unformatted manual pages exist
  59.     in man/man1 and man/man3 and should be copied to your system's manual page
  60.     directory.  If you don't have the nroff command installed on your system
  61.     then you may also need to copy the formatted manual pages, located in
  62.     man/cat1 and man/cat3.  You may also need to modify your MANPATH environment
  63.     variable if you installed the manual pages in a non-standard place, and some
  64.     systems require you to update the whatis database after installing new
  65.     manual pages, by running makewhatis, catman or equivalent.  Note that there
  66.     are two manual pages for mpatrol with the same name and you are likely to
  67.     see the section 1 manual page by default.  You must explicitly specify the
  68.     section number when using the man command in order to view the other manual
  69.     page.
  70.  
  71.  
  72.  2. BUILDING
  73.  
  74.  Q. Why does the makefile assume that I am building mpatrol on platform X when
  75.     I am really building on platform Y?
  76.  
  77.  A. The src/config.h and src/target.h header files attempt to obtain as much
  78.     information from the compiler as possible, mainly from any predefined
  79.     preprocessor macros that it defines during compilation.  If this information
  80.     is incorrect then you can override the TARGET, SYSTEM, ARCH and FORMAT
  81.     preprocessor macros defined in src/target.h to suit your particular system
  82.     by explicitly defining them in CFLAGS within the makefile when you build
  83.     mpatrol.  You could also choose to build different versions of mpatrol with
  84.     different settings of FORMAT on a single system if you wish to by changing
  85.     FORMAT for different builds.
  86.  
  87.  Q. I cannot include mpatrol.h from my C++ source code as I get lots of
  88.     compilation errors.  Why is this and what can I do to prevent them?
  89.  
  90.  A. The most likely reason that you are getting errors is because you are
  91.     calling placement new, and the way that mpatrol derives source information
  92.     from calls to operator new is by defining a macro called new, thus causing
  93.     lots of problems when calling placement new or explicitly calling operator
  94.     new.  You can either try not to use placement new or you can define the
  95.     preprocessor macro MP_NOCPLUSPLUS when compiling your source file, which
  96.     will disable the overriding of any C++ operators in mpatrol.h.
  97.  
  98.  Q. I still have the above problem, but I don't think it's due to placement
  99.     new since the compiler complains about operator new[], so could that be a
  100.     clue?
  101.  
  102.  A. Yes.  The most likely reason is that the C++ compiler does not support
  103.     the array new and delete operators.  These were introduced some time
  104.     before the standardisation of the C++ language but some compilers may not
  105.     yet have support for them.  It may be that you have to use a special
  106.     compiler option to enable support for these operators, but if not you will
  107.     probably have to edit mpatrol.h to temporarily allow your files to compile.
  108.  
  109.  Q. Why do some of the makefiles contain the -fno-inline-functions option as
  110.     part of OFLAGS?
  111.  
  112.  A. The -fno-inline-functions option is a GCC-specific option which instructs
  113.     the compiler not to inline any functions.  This is necessary on some
  114.     platforms where function call stack traversal is supported, since function
  115.     inlining may significantly alter the layout of a program's stack.  Normally
  116.     this option is only required when building the mpatrol library, but on some
  117.     platforms function call stack traversal may not work properly unless this
  118.     option (or equivalent) is used for all compiled code.
  119.  
  120.  
  121.  3. LINKING
  122.  
  123.  Q. Why do I get undefined symbols when linking with the mpatrol library?
  124.  
  125.  A. This is most likely caused by the mpatrol library requiring additional
  126.     symbols defined in an object file access library.  If mpatrol was built with
  127.     FORMAT=FORMAT_ELF32 then you'll need to add -lelf (or equivalent) to the
  128.     compiler command line straight after -lmpatrol.  If mpatrol was built with
  129.     FORMAT=FORMAT_BFD then you'll need to add -lbfd -liberty (or equivalent)
  130.     instead.  If you are using the thread-safe version of mpatrol then you may
  131.     also need to link with the system threads library.
  132.  
  133.  Q. Why do I get duplicate definitions of symbols when linking with the mpatrol
  134.     library?
  135.  
  136.  A. This is most likely caused by your code, or a library, providing definitions
  137.     of malloc() and free() which conflict with those defined in the mpatrol
  138.     library.  You'll need to disable these in order to perform a successful link
  139.     and use the replacements in mpatrol instead.
  140.  
  141.  Q. I linked my program to a shared library version of mpatrol.  Now, when I try
  142.     to run my program, the system complains that it cannot find the mpatrol
  143.     library.  How do I get this to work?
  144.  
  145.  A. You need to tell the system where to find the shared library version of the
  146.     mpatrol library, either by setting your LD_LIBRARY_PATH environment variable
  147.     (or just PATH on Windows platforms), or by embedding the full path to the
  148.     library into the executable when you link your program by setting the
  149.     LD_RUN_PATH environment variable.
  150.  
  151.  Q. I linked my program to a shared library version of mpatrol.  Will future
  152.     releases of mpatrol remain compatible with this version or will I have to
  153.     relink my program?
  154.  
  155.  A. Backwards compatibility is not generally guaranteed, but should be preserved
  156.     if only the bug fix part of the mpatrol version number has changed, with the
  157.     major and minor versions staying the same.  For example, versions 1.0.3 and
  158.     1.0.8 should be compatible, but upgrading to version 1.1.0 may require a
  159.     relink.
  160.  
  161.  Q. I have linked my program with the DLL version of the mpatrol library on
  162.     Windows but it crashes when I run it.  I suspect that the crash is occurring
  163.     when the mpatrol library is being initialised, so what is going wrong?
  164.  
  165.  A. There appears to be a problem when using the mpatrol DLL and the static
  166.     version of the Microsoft C run-time library, and also a problem when using
  167.     the static version of mpatrol and the Microsoft C run-time library DLL.
  168.     Luckily, if you ensure that you use either both static libraries or both
  169.     DLLs at the same time then the problem should go away.  There doesn't seem
  170.     to be an easier way around it at this time or, for that matter, an
  171.     explanation for why it happens
  172.  
  173.  
  174.  4. RUNNING
  175.  
  176.  Q. I've just linked and run my program with the mpatrol library, but the
  177.     resulting log file doesn't contain any useful information.  Why does it not
  178.     contain a list of all memory transactions or show any unfreed memory
  179.     allocations?
  180.  
  181.  A. By default, the mpatrol library will only write a summary of library
  182.     settings and statistics to the log file, and that will only occur on
  183.     successful program termination (i.e. when exit() is called).  If this does
  184.     not appear then it is likely that your program (or some other library
  185.     function) called abort() due to a fatal error.  However, there are a
  186.     multitude of different options that you can pass to the mpatrol library via
  187.     the MPATROL_OPTIONS environment variable that will allow you to control what
  188.     is logged and what is not.  Note that the mpatrol command will always log
  189.     all calls to allocate, reallocate and free memory by default.
  190.  
  191.  Q. I linked my program with the mpatrol library to trace all of its memory
  192.     operations, such as memcpy() and memcmp(), but I get nothing in the log
  193.     file.  Why is this?
  194.  
  195.  A. The memory operation functions do not automatically initialise the mpatrol
  196.     library since on many systems the startup routines call them very early on.
  197.     If your program does not call any memory allocation functions to initialise
  198.     the mpatrol library then you must explicitly call the __mp_init() function.
  199.     All memory operation functions following that call with then be traced.
  200.  
  201.  Q. Why does the USEDEBUG option not work for me?
  202.  
  203.  A. Firstly, you have to ensure that you have built the mpatrol library with
  204.     support for the GNU BFD object file access library by compiling with the
  205.     FORMAT=FORMAT_BFD preprocessor macro definition.  Secondly, you have to
  206.     ensure that you have compiled all relevant object files with debugging
  207.     information enabled (usually by adding an option to the compiler command
  208.     line), although the mpatrol library does not need to be compiled this way.
  209.     The file and line number information will hopefully then appear in the
  210.     log file for all symbols that have associated debugging information.
  211.  
  212.  Q. Why do some mpatrol log file entries only contain a partial call stack
  213.     rather than following the function call stack back to the call to main()?
  214.  
  215.  A. This could be because the mpatrol library was compiled with limited call
  216.     stack traversal support via the MP_BUILTINSTACK_SUPPORT configuration macro.
  217.     However, it could also mean that the mpatrol library encountered a corrupt
  218.     frame pointer when traversing the call stack and had to terminate the
  219.     recursion.  The frame pointer MUST be preserved from function to function
  220.     on most platforms, otherwise the stack cannot be traversed.  See your
  221.     compiler manual for further details.
  222.  
  223.  Q. I am trying to use the mpatrol command to debug an executable file that was
  224.     not originally compiled with the mpatrol library.  However, even though it
  225.     runs successfully, no mpatrol log file is produced.  Why is this?
  226.  
  227.  A. First, check that you are passing the -d option to the mpatrol command.
  228.     If that doesn't work then check that the executable file has been
  229.     dynamically linked; statically linked executables cannot be forced to use
  230.     the mpatrol library.  If it still doesn't work then it may be that the
  231.     dynamic linker on your system doesn't have the ability to preload any shared
  232.     libraries that have been specified in a special environment variable, in
  233.     which case you can't use this feature.
  234.  
  235.  Q. I know that there's a definite heap corruption problem in my program as it
  236.     keeps crashing in unrelated code due to pointer corruption, and when I link
  237.     with the mpatrol library it stops crashing.  What can I do?
  238.  
  239.  A. Try as many of the relevant mpatrol run-time options as possible and make
  240.     sure that you closely examine the mpatrol log file for warnings and errors -
  241.     your problem may have been noticed by the mpatrol library but it may not
  242.     have considered it a fatal error and continued execution.  If this still
  243.     doesn't show up anything then you can probably rest assured that you have a
  244.     memory corruption problem but you may need to use a commercial product such
  245.     as Purify to isolate it.  If that fails then you'll just have to employ the
  246.     traditional debugging method of single-stepping through your program in a
  247.     debugger until something unusual or unexpected happens.
  248.  
  249.  Q. If I link my program to version 1.0 of the mpatrol library then I cannot
  250.     interrupt it using the keyboard, which I would normally be able to do
  251.     without using mpatrol.  Is this a bug?
  252.  
  253.  A. Not really, but it is undesirable behaviour in most cases, which is why it
  254.     was removed in later releases of mpatrol and replaced with the SAFESIGNALS
  255.     option.  The reason that the program could not be interrupted using the
  256.     keyboard was that mpatrol would ignore such signals when its library code
  257.     was being executed, otherwise user-defined signal handlers that used
  258.     malloc() and related functions would have the capability to cause lots of
  259.     undesirable side effects.  However, this does not normally happen, which is
  260.     why the behaviour was moved to an option for those that needed it.
  261.  
  262.  Q. I've linked and run my program with mpatrol under UNIX and it uses a large
  263.     amount of heap memory.  However, it crashes near the end of execution and
  264.     then proceeds to freeze up the whole system, sometimes requiring a reboot.
  265.     What am I doing wrong?
  266.  
  267.  A. The most common possible explanation for this is that you are running your
  268.     program with too much access to system resources.  What is likely to be
  269.     happening is that when your program crashes the system attempts to dump the
  270.     entire process image to a core file for later debugging in a non-symbolic
  271.     debugger.  If the process has a huge heap then the core file is also going
  272.     to be huge, thus resulting in a massive file that may lead to the system
  273.     thrashing while it attempts to write it to the disk.  Technically, the
  274.     system has not frozen, but it is likely to take a long time to finish
  275.     writing the file.  The best solution involves setting your program's maximum
  276.     core file size to a reasonable limit (or just zero), and also possibly
  277.     limiting your program's maximum data segment size as well.  These can be set
  278.     from the shell but the exact details on how to do this differ between
  279.     shells.
  280.  
  281.  Q. Why does my program run so slowly after I link it with the mpatrol library?
  282.  
  283.  A. Normal malloc libraries are optimised for speed but will typically fall over
  284.     at the slightest hint of an error.  Debugging malloc libraries are written
  285.     to provide as much debugging information as possible whilst performing a
  286.     multitude of additional checks, which is why they may run much slower.
  287.     However, you can control which checks are performed (and when) by using the
  288.     MPATROL_OPTIONS environment variable.  Performance may also be lost if you
  289.     make lots of small memory allocations rather than fewer larger allocations,
  290.     but that is mainly due to the overhead of storing the extra tracing details
  291.     for each memory allocation.
  292.  
  293.  Q. My program is written in C++ and is linked to the mpatrol library, but how
  294.     do I go about demangling the C++ symbol names that are shown in the stack
  295.     tracebacks in the resulting log file?
  296.  
  297.  A. Because there is no standard way of mangling C++ symbol names, various
  298.     compilers and operating systems have taken different approaches to C++ name
  299.     mangling, many of which differ significantly from the method suggested in
  300.     The Annotated C++ Reference Manual by Margaret Ellis and Bjarne Stroustrup.
  301.     However, most compilers come with a demangling tool which can be used in a
  302.     command pipe to accept mangled names on its standard input file stream and
  303.     demangle them on its standard output file stream, and so can be used to
  304.     process the mpatrol log file.
  305.  
  306.  Q. Why does my program not stop when the mpatrol library notices an error?
  307.  
  308.  A. The library was written to give as much information as possible and so
  309.     sometimes, when a non-fatal error is discovered, the library will write
  310.     the error message to the log file and continue in the hope of being able
  311.     to uncover more errors during the execution of the program.  This means
  312.     that you should always check the number of warnings and errors given in
  313.     the summary at the end of program execution, and then search backwards in
  314.     the log file for WARNING or ERROR.
  315.  
  316.  Q. I have linked my program with the mpatrol library on an Amiga or Netware
  317.     machine, but when it runs it still crashes the entire system.  Why is
  318.     this?
  319.  
  320.  A. AmigaOS and Netware do not have virtual memory and so do not have memory
  321.     protection turned on by default.  This means that any rogue write to an
  322.     erroneous address may actually overwrite the data of another process or
  323.     perhaps even the operating system, thus bringing the entire machine down.
  324.     There are several third-party system utilities available for the Amiga to
  325.     add memory protection to machines with built-in MMUs, which can then be
  326.     used in conjunction with mpatrol.  I'm not sure about the availability of
  327.     such software for Netware.
  328.  
  329.  Q. I have built the mpatrol library with GCC on AmigaOS and have successfully
  330.     linked it to my program.  However, why are none of the options in the
  331.     MPATROL_OPTIONS environment variable recognised when I run it?
  332.  
  333.  A. The getenv() function in the GNU C library is not compatible with the
  334.     AmigaDOS SetEnv and GetEnv commands since it does not treat environment
  335.     variables as files located in ENV: and is only compatible with software
  336.     that uses the ixemul library.  However, the env command that comes with
  337.     most GNU software distributions allows you to set an environment variable
  338.     that the GNU getenv() function can read when you are running in AmigaDOS.
  339.  
  340.  Q. How do I suppress all diagnostic output from the mpatrol library?
  341.  
  342.  A. You can do this by setting the mpatrol log file to be your system's "bit
  343.     bucket", which is /dev/null on UNIX platforms and NIL: on AmigaOS.  There
  344.     doesn't appear to be an equivalent way to do this on Windows or Netware.
  345.  
  346.  
  347.  5. FILES
  348.  
  349.  Q. Why is there a libmpatrol.o target in the UNIX and Amiga Makefiles?
  350.  
  351.  A. This is simply used to build the mpatrol library as one large object file
  352.     for full incorporation into other libraries and was used during the
  353.     development of mpatrol.  On UNIX platforms some linkers support the -r
  354.     option for combining many object files into one large object file, but this
  355.     is not universally supported, hence the reason for using the compiler
  356.     instead.  Because all of the source files are compiled at once, there may be
  357.     conflicts with system header files when malloc() and its related functions
  358.     are being compiled, which is why such an object file is not built by
  359.     default.  Note that the Windows and Netware Makefiles use libmpatrol.obj.
  360.  
  361.  Q. What are the CVS subdirectories that come with the mpatrol distribution?
  362.  
  363.  A. CVS stands for Concurrent Versions System and is a project version control
  364.     system.  All of the source files that comprise an mpatrol release are stored
  365.     in a central CVS repository so that previous releases can be easily
  366.     retrieved, but the CVS system needs to have a way of determining the
  367.     versions of currently checked-out files, hence the CVS subdirectories.  You
  368.     shouldn't need to worry about them, so just ignore them.
  369.  
  370.  Q. What does the mupdate shell script do?
  371.  
  372.  A. This is for my use in order to automate every new release of mpatrol.  You
  373.     should never need to run this script and it should not be installed
  374.     anywhere on your system.  This script also uses and modifies the VERSION
  375.     file and updates the NEWS and ChangeLog files.
  376.